home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / Dev / Amiga-E / E_v3.2a / Src / Gfx / IfsFern.e < prev    next >
Text File  |  1992-09-02  |  1KB  |  57 lines

  1. /* iterated affine transformations 
  2.  
  3.    gets you a leaf on the screen in a rather special way.
  4.    be patient: it may take some time for you to actually see something.
  5.  
  6. */
  7.  
  8. OPT OSVERSION=39  /* oh, and we need a 640*512*256 screen */
  9.  
  10. CONST SCRX=740, SCRY=580, PLANES=8
  11.  
  12. OBJECT trans
  13.   a,b,c,d,ox,oy,prob
  14. ENDOBJECT
  15.  
  16. DEF win,scr
  17.  
  18. PROC main()
  19.   DEF a
  20.   scr:=OpenS(SCRX,SCRY,PLANES,$8004,'Fern')
  21.   IF scr=NIL
  22.     WriteF('Could not open screen!\n')
  23.   ELSE
  24.     win:=OpenW(0,0,SCRX-1,SCRY-1,$200,$F,'Fern',scr,15,NIL)
  25.     IF win=NIL
  26.       WriteF('Could not open window!\n')
  27.     ELSE
  28.       FOR a:=0 TO 255 DO SetColour(scr,a,a,a,a)
  29.       do([[  .0,   .0,   .0,  .16,.0, .0, 1 ]:trans,   -> back to the root!
  30.           [  .2,   .23,(-.26),.22,.0,1.6, 7 ]:trans,   -> right leaf
  31.           [(-.15), .26,  .28, .24,.0, .44,7 ]:trans,   -> left leaf
  32.           [  .85,(-.04), .04, .85,.0,1.6, 85]:trans])  -> body
  33.       ->WaitIMessage(win)
  34.       CloseW(win)
  35.     ENDIF
  36.     CloseS(scr)
  37.   ENDIF
  38. ENDPROC
  39.  
  40. PROC do(t:PTR TO LONG)
  41.   DEF x=1.,y=1.,r,n,a,tr:PTR TO trans,xn,yn,sx,sy,d
  42.   REPEAT
  43.     r:=Rnd(100)
  44.     n:=0
  45.     FOR a:=1 TO ListLen(t)
  46.       tr:=t[a-1]
  47.     EXIT (r>=n) AND (tr.prob+n>r)
  48.       n:=n+tr.prob
  49.     ENDFOR
  50.     sx:=!(xn:=!(!tr.a*x)+(!tr.c*y)+tr.ox)*60.!+(SCRX/2)
  51.     sy:=SCRY-(!(yn:=!(!tr.b*x)+(!tr.d*y)+tr.oy)*50.!)
  52.     d:=Bounds(ReadPixel(stdrast,sx,sy)+20,64,255)
  53.     Plot(sx,sy,d)
  54.     x:=xn; y:=yn
  55.   UNTIL LeftMouse(win)
  56. ENDPROC
  57.